(function (win) {
    const doc = win.document;
    const docEl = doc.documentElement;

    // 设置 1rem = 100px
    function setRemUnit() {
        const clientWidth = docEl.clientWidth;
        // 以750px设计稿为基准
        const rem = clientWidth / 7.5;
        docEl.style.fontSize = rem + 'px';
    }

    // 初始化
    setRemUnit();

    // 窗口变化时重新计算
    win.addEventListener('resize', setRemUnit);
    win.addEventListener('pageshow', function (e) {
        if (e.persisted) {
            setRemUnit();
        }
    });

})(window); 